<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="../../../static/layui/css/layui.css">
    <script src="../../../static/js/jquery-3.3.1.min.js"></script>
    <script src="../../../static/layui/layui.js"></script>

</head>
<body>
<script type="text/html" id="checkboxTpl">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="status" value="{{d.status}}" title="审核通过" lay-filter="lockDemo" {{ d.status === 1? "checked": "" }}>
</script>


<table id="AllTeacherList" lay-filter="test" lay-data="{id: 'courseNowRow'}"></table>



<script>
    layui.use('table', function () {
        var table = layui.table
            ,form = layui.form;

        //第一个实例
        var tableDate = table.render({
            elem: '#AllTeacherList'
            , id: "courseNowRow"
            , title: "教师信息"
            , toolbar: 'default'
            , height: 550
            , even: true
            // , size: "lg"
            , url: '${pageContext.request.contextPath}/queryAllTeacher' //数据接口
            , page: true //开启分页
            //,totalRow:true
            ,cols: [[
                {type:'checkbox'},
                {field: 'teacherId', title: '教师ID', align:'center', width: 120, sort: true}
                , {field: 'teacherPassword', title: '教师密码', align:'center', width: 120, sort: true}
                , {field: 'teacherName', title: '教师名字', align:'center', width: 120, sort: true}
                , {field: 'teacherGrade', title: '教师级别', align:'center', width: 100, sort: true}
                //, {field: 'courseCredit', title: '课程学分', align:'center', width: 100, sort: true}
                , {field: 'teacherType', title: '教师类型', align:'center', width: 100, sort: true}
                , {field: 'department', title: '所属系部', align:'center', width: 160, sort: true}
               // , {field: 'status', title: '状态',templet: '#checkboxTpl', align:'center', width: 120, sort: true}
                ,{field: 'teacherDesc', title: '个人描述', align:'center', width: 160}
            ]]
        });


        //监听行单击事件
        table.on('row(test)', function(obj){
            // console.log(obj.tr) //得到当前行元素对象
            //console.log(obj.data)
            var data = obj.data;
            layer.msg("教师名："+data.teacherName) //得到当前行数据


        });



        //监听事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    layer.msg('添加~ 暂不开放！',{icon:"5"});

                    break;
                case 'delete':
                    console.log(checkStatus.data)
                    var data = checkStatus.data;
                    if(data.length!=0){

                        var teacherList = new Array(data.length);

                        for(var i =0;i<data.length;i++){
                            var teacher = {
                                "teacherId":data[i].teacherId
                            };
                            teacherList[i] = teacher;
                        }

                        $.post(
                            "${pageContext.request.contextPath}/adminDeleteTeacher",
                            JSON.stringify(teacherList),
                            function (data) {
                                layer.msg("成功删除:"+data+"名教师!",{icon:"6"});
                                tableDate.reload()
                            }

                        )
                    }
                    break;
                case 'update':
                    layer.msg('编辑~ 暂不开放！',{icon:"5"});
                    break;
            };
        });

        //监听锁定操作
        form.on('checkbox(lockDemo)', function(obj){
            console.log(obj)
            layer.tips(this.value + ' ' + this.name + '：'+ obj.elem.checked, obj.othis);
        });

    });



</script>


</body>
</html>
